﻿using Autofac;
using Gfinder.Crosscutting;
using MongoDB.Driver;

namespace Gfinder.Data
{
    public class DataModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            var mongoClient = new MongoClient(ApplicationSettings.DatabaseHost);
            var database = mongoClient.GetDatabase(ApplicationSettings.DatabaseName);
            builder.RegisterInstance(mongoClient).As<IMongoClient>().SingleInstance();
            builder.RegisterInstance(database).As<IMongoDatabase>();
            builder.RegisterAssemblyTypes(typeof (DataModule).Assembly)
                   .Where(x => x.Name.EndsWith("Repository"))
                   .AsImplementedInterfaces();

            base.Load(builder);
        }
    }
}
